package com.nattakute.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nattakute.dao.RequestDAO;
import com.nattakute.model.Request;

@Repository("requestDao")
public class RequestDAOImpl implements RequestDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	
	public List<Request> getRequest() {
		return sessionFactory.getCurrentSession().createQuery("from Request").list();
	}

	
	public Request getRequestById(Integer id) {
		Request request = null;
		try {
			request = (Request)sessionFactory.getCurrentSession().get(Request.class, id);
			return request;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}

	
	public Boolean addRequest(Request request) {
		try {
			sessionFactory.getCurrentSession().save(request);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	
	public Boolean deleteRequest(Request request) {
		try {
			sessionFactory.getCurrentSession().delete(request);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	
	public Boolean updateRequest(Request request) {
		try {
			sessionFactory.getCurrentSession().update(request);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	
	public List<Request> getRequestByTimetable() {
		// TODO Auto-generated method stub
		return null;
	}

}
